import Vue from 'vue'
import App from './App.vue'
import MuseUI from 'muse-ui'
import VueRouter from 'vue-router'
import 'muse-ui/dist/muse-ui.css'
import echarts from 'echarts'
import VueResource from 'vue-resource'
import VueECharts from 'vue-echarts/components/ECharts.vue'
import Vuex from 'vuex'
import 'echarts/lib/chart/bar'
import 'echarts/lib/chart/pie'
import 'echarts/lib/chart/line'
import 'echarts/lib/component/tooltip'


Vue.use(VueRouter)
Vue.use(MuseUI)
Vue.use(VueResource)
Vue.use(Vuex)
Vue.component('chart', VueECharts)

import login from "./component/login.vue"
import regist from "./component/regist.vue"
import index from "./component/index.vue"
import history from "./component/history.vue"
import reports from "./component/reports.vue"
import setting from "./component/setting.vue"
import diary from "./component/diary.vue"

const store = new Vuex.Store({
	state:{
		uid: 100001,
		username: "",
		remark: "",
	},
	mutations:{
		// setPlayList(state,playList){
		// 	state.playList = playList.list;
		//     state.index = playList.index;
		//     state.song = state.playList[state.index];
		//     state.playing = true;
		// },
		setBaseInfo(state,baseInfo){
			state.username = baseInfo.username
			state.remark = baseInfo.remark
			state.uid = baseInfo.uid
		}
		
	},
	getters: {
	    getBaseInfo: state => {
	      return state;
	    },
	    duration: state => {
	      return parseInt(state.duration / 60) + ':' + (Array(2).join(0) + (state.duration % 60)).slice(-2)
	    }
	}
})

const routes = [
	{ path: '/login', component: login },
	{ path: '/regist', component: regist },
	{ path: '/index', component: index ,
		children: [
			{ path: 'history', component: history},
			{ path: 'report', component: reports },
			{ path: 'setting', component: setting },
			{ path: 'diary', component: diary },
		]
	},
  	{ path: '', redirect: '/index'}
]

const router = new VueRouter({
  routes // （缩写）相当于 routes: routes
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
